//
//  UIManager.swift
//  CandyDate
//
//  Created by zolobdz on 2017/9/26.
//  Copyright © 2017年 HeChao. All rights reserved.
//

import UIKit
import Toaster
import SVProgressHUD
import TZImagePickerController

class UIManager {

    lazy var mainWindow = UIWindow()
    lazy var tabBarController = MainTabBarController()
    // 被挤下线提示
    lazy var shouldShowKickedAlert = false
    lazy var kickedMessage = ""
    
    static let shared = UIManager.init()
    private init(){}

    func setup() {
        mainWindow.frame = UIScreen.main.bounds
        mainWindow.backgroundColor = UIColor.white
        mainWindow.makeKeyAndVisible()
        mainWindow.rootViewController = tabBarController
        AppDelegate.shared().window = mainWindow

        // UINavigationBar setup
        let navigationBar = UINavigationBar.appearance()
        navigationBar.isExclusiveTouch = true
        // 以下几个属性交给各个navi自己控制
        navigationBar.isTranslucent = false
//        navigationBar.backIndicatorImage = R.image.navi_back()!.withRenderingMode(.alwaysOriginal)
        navigationBar.titleTextAttributes = [NSAttributedStringKey.foregroundColor: UIColor.white]
        navigationBar.tintColor = UIColor.white
        navigationBar.setBackgroundImage(CDUtility.createImageWithColor(color: CDColor.themePink), for: UIBarMetrics.default)
//        navigationBar.setBackgroundImage(CDUtility.createImageWithColor(color: UIColor.white), for: UIBarMetrics.default)
        
//        TZImageManager.default().
        
        // Toaster
        ToastView.appearance().font =  UIFont.systemFont(ofSize: 15)
        ToastView.appearance().bottomOffsetPortrait = DeviceInfo.screenHeight / 2.0
        ToastView.appearance().backgroundColor = UIColor(white: 0, alpha: 0.4)
        
        // SVProgressHUD
        SVProgressHUD.setForegroundColor(UIColor.white)
        SVProgressHUD.setBackgroundColor(UIColor.black.withAlphaComponent(0.6))
//        SVProgressHUD.setSuccessImage(UIImage(resource: R.image.hud_success)!)
        SVProgressHUD.setMinimumSize(CGSize(width: 100.0, height: 100.0))
        SVProgressHUD.setImageViewSize(CGSize(width: 48.0, height: 48.0))
        SVProgressHUD.setDefaultMaskType(SVProgressHUDMaskType.clear)
        
        // UITableView ios11 bug如果不这么设置上拉加载更多时会多次上拉。因为ios11默认开启了self-sizing
        let tableView = UITableView.appearance()
        tableView.estimatedRowHeight = 0.0
        tableView.estimatedSectionFooterHeight = 0.0
        tableView.estimatedSectionHeaderHeight = 0.0
        tableView.layoutMargins = UIEdgeInsets.zero
        tableView.separatorInset = UIEdgeInsets.zero
        tableView.separatorColor = CDColor.cellSeparatorLineColor

        
    }
    
    func showQRPage(qrString: String) {
        
        let qrController = QRCodeViewController()
        qrController.dataString = qrString
        let nav = BaseNavigationController(rootViewController: qrController)
        tabBarController.present(nav, animated: true) {
            
        }
    }
    
}
